﻿using Super_Management_Mayhem.Content.Animations.Native;
using Super_Management_Mayhem.Control;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Helper;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Players.Native
{
    public partial class Native
    {
        public enum NativeType
        {
            Regular,
            Backslide,
            TriArrow,
        }

        private NativeType _nativeType;

        public Native(TE_Vector2 position, Color skinColor, InputKeys input, PlayerContainer playerContainer, TE_Vector2 previousCameraPosition, NativeType _type) 
            : base(position, skinColor, input, playerContainer, previousCameraPosition)
        {
            _nativeType = _type;
        }

        protected override float WalkSpeed
        {
            get
            {
                return 12;
            }
        }

        protected override void InitializeCreationState()
        {
            CallMethod(1000, () => ChangeState(PlayerState.Idle));

            SetIdleModel(Direction.Down);
        }

        protected override void AttackEnd()
        {
            switch (_latestDirection)
            {
                case Direction.Up:
                    Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition, -TE_Vector2.UnitY, 4, _statistics.GetTeam()));
                    if (_nativeType == NativeType.TriArrow)
                    {
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(16, -16), -TE_Vector2.UnitY.Rotate(-0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(-12, -16), -TE_Vector2.UnitY.Rotate(0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                    }
                    break;
                case Direction.Down:
                    Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition, TE_Vector2.UnitY, 4, _statistics.GetTeam()));
                    if (_nativeType == NativeType.TriArrow)
                    {
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(-12, 20), TE_Vector2.UnitY.Rotate(-0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(16, 20), TE_Vector2.UnitY.Rotate(0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                    }
                    break;
                case Direction.Left:
                    Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition, -TE_Vector2.UnitX, 4, _statistics.GetTeam()));
                    if (_nativeType == NativeType.TriArrow)
                    {
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(0, 4), -TE_Vector2.UnitX.Rotate(-0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(0, -4), -TE_Vector2.UnitX.Rotate(0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                    }
                    break;
                case Direction.Right:
                    Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition, TE_Vector2.UnitX, 4, _statistics.GetTeam()));
                    if (_nativeType == NativeType.TriArrow)
                    {
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(0, -4), TE_Vector2.UnitX.Rotate(-0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                        Playscreen.Map.AddParticle(new Arrow(_player.AbsolutePosition.Offset(0, 4), TE_Vector2.UnitX.Rotate(0.03125.TimesTwoPi()), 2, _statistics.GetTeam()));
                    }
                    break;
            }

            base.AttackEnd();
        }

        protected override double GetAttackTime(Direction direction)
        {
            switch (direction)
            {
                case Direction.Up:
                    return AttackUpState.Duration;
                case Direction.Down:
                    return AttackDownState.Duration;
                case Direction.Left:
                    return AttackLeftState.Duration;
                case Direction.Right:
                    return AttackRightState.Duration;

            }

            return -1;
        }


        protected override void UpdateAttackState(System.TimeSpan gameTime)
        {
            //Don't attack, let the arrow do the job
        }
    }
}